package cn.lingyangwl.agile.pay.pay.controller.payorder;

import cn.lingyangwl.agile.pay.common.annotation.PayCheck;
import cn.lingyangwl.agile.pay.pay.model.rqrs.payorder.UnifiedOrderExtRQ;
import cn.lingyangwl.framework.core.response.Resp;
import cn.lingyangwl.agile.common.security.annotation.Anonymous;
import cn.lingyangwl.agile.pay.model.rqrs.pay.payorder.ContinuePayRQ;
import cn.lingyangwl.agile.pay.validation.PaySignGroup;
import cn.lingyangwl.agile.pay.pay.process.payorder.UnifiedOrderProcess;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 统一下单 controller
 */
@Slf4j
@RestController
@Anonymous
public class UnifiedOrderController {

    @Resource
    private UnifiedOrderProcess unifiedOrderProcess;

    /**
     * 统一下单接口
     */
    @PostMapping("/pay/unifiedOrder")
    @PayCheck
    public Resp<?> unifiedOrder(@RequestBody @Validated(value = PaySignGroup.class) UnifiedOrderExtRQ rq) {
        return unifiedOrderProcess.unifiedOrder(rq);
    }


    /**
     * 继续去支付接口, 户很有可能点击付款后, 然后退出去了, 并没有付款, 此时订单处于未支付状态, 用户可以在 <br/>
     * 待支付页面, 继续支付未完成的订单
     */
    @PostMapping("/pay/continuePay")
    @PayCheck
    public Resp<?> continuePay(@RequestBody @Validated(value = PaySignGroup.class) ContinuePayRQ rq) {
        return unifiedOrderProcess.continuePay(rq);
    }

}
